<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #template {
        display: none;
      }
    </style>
  </head>
  <body>
    <!-- dynamicComponent -->
    <!-- <div v-is="view"></div> -->

    <div id="template">
      <keep-alive include="View2">
        <component :is="view"></component>
      </keep-alive>
      <button @click="toggleView">切换</button>
    </div>
    <div id="app"></div>
    <script src="../../../../packages/vue/dist/vue.global.js"></script>

    <script>
      const { createApp, ref } = Vue

      const template = document.querySelector('#template')?.innerHTML
      const App = {
        setup() {
          const toggle = ref(true)
          const view = ref('View')
          const toggleView = () => view.value = view.value === 'View' ? 'View2' : 'View'
          return {
            view,
            toggleView
          }
        },
        components: {
          View: {
            name: 'View',
            template: `<h1>1111</h1>`
          },
          View2: {
            name: 'View2',
            template: `<h1>222</h1>`
          }
        },
        template
      }

      createApp(App).mount('#app')
    </script>
  </body>
</html>
